package com.free.semantic.infrastruct.mapper;

import com.free.semantic.infrastruct.common.RelationDefineItemDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RelationDefineItemMapper {
    
    @Select("SELECT * FROM relation_define_item WHERE id = #{id}")
    RelationDefineItemDO findById(@Param("id") Long id);
    
    @Select("SELECT * FROM relation_define_item WHERE relation_define_id = #{relationDefineId}")
    List<RelationDefineItemDO> findByRelationDefineId(@Param("relationDefineId") Long relationDefineId);
    
    @Insert("INSERT INTO relation_define_item(relation_define_id, relation_define, create_time, update_time) " +
            "VALUES(#{relationDefineId}, #{relationDefine}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(RelationDefineItemDO relationDefineItemDO);
    
    @Update("UPDATE relation_define_item SET relation_define_id = #{relationDefineId}, " +
            "relation_define = #{relationDefine}, update_time = NOW() WHERE id = #{id}")
    int update(RelationDefineItemDO relationDefineItemDO);
    
    @Delete("DELETE FROM relation_define_item WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
    
    @Delete("DELETE FROM relation_define_item WHERE relation_define_id = #{relationDefineId}")
    int deleteByRelationDefineId(@Param("relationDefineId") Long relationDefineId);
} 